{{ define "chat/register.html" }}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,maxinum-scale=1">
    <title> 我的IM {{.title}}</title>
    <link rel="stylesheet" href="/static/mui/css/mui.min.css">
    <script src="/static/js/axios.min.js"></script>
    <script src="/static/js/vue.min.js"></script>
    <script src="/static/mui/js/mui.js"></script>
</head>
<body>
<header class="mui-bar mui-bar-nav">
    <h1 class="mui-title">注册</h1>
</header>
<div class="mui-content" id="pageapp">
    <form id="login-form" class="mui-input-group">
        <div class="mui-input-row">
            <label>账户</label>
            <input v-model="user.name" placeholder="请输入用户名" type="text" class="mui-input-clear">
        </div>
        <div class="mui-input-row">
            <label>账户</label>
            <input v-model="user.password" placeholder="请输入密码" type="password" class="mui-input-clear">
        </div>
        <div class="mui-input-row">
            <label>账户</label>
            <input v-model="user.repassword" placeholder="请输入密码" type="password" class="mui-input-clear">
        </div>
    </form>
    <div class="mui-content-padded">
        <button @click="login" type="button" class="mui-btn mui-btn-block mui-btn-primary">注册</button>
        <div class="link-area"><a id="reg" href="/login">登陆账号</a> <span class="spliter">|</span><a id="pwd" href="pwd">忘记密码</a> </div>
    </div>

</div>
</body>
</html>
<script>
    var app = new Vue({
        el:"#pageapp"
        ,data:function (){
            return {
                user:{
                    name:"",
                    password:"",
                    repassword:"",
                }
            }
        },
        methods:{
            login:function (){
                //监测手机号是否正确
                console.log("login")
                //检测密码是否为空

                //网络请求
                //封装了promis
                let aa = {
                    name:this.user.name,
                    password:this.user.password,
                    repassword:this.user.repassword
                }

                axios({
                    url:'/api/user/create',
                    method:'post',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                        Accept: 'application/json'
                    },
                    data:aa
                }).then(res=>{
                    console.log(res)
                    if (res.data.code!=1){
                        mui.toast(res.data.message)
                        // alert(res.data.message)
                    }else{
                        location.replace("//localhost/login")
                        mui.toast("注册成功，即将跳转")
                    }
                })
            }
        },
    })
</script>

{{ end }}